package com.qf.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.commo.utils.R;
import com.qf.entity.Role;
import com.qf.entity.User;
import com.qf.service.IRoleService;
import com.qf.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private IRoleService roleService;
    //添加用户
    @PostMapping("/saveRole")
    public R save(@RequestBody Role role){
        System.out.println(role);
        boolean save =roleService.save(role);
        return R.out(save);
    }
    //分页
    @PostMapping("/page")
    public R page(@RequestBody Page<Role> page){
        page =roleService.page(page);
        return R.putDate("page",page);
    }
    //通过id查询用户
    @GetMapping("/getById/{id}")
    public R getById(@PathVariable Integer id){
        Role role = roleService.getById(id);
        System.out.println(role);
        return R.putDate("data",role);
    }
    //删除用户
    @GetMapping("/delete/{id}")
    public R delete(@PathVariable Integer id){
        boolean b = roleService.removeById(id);
        return R.out(b);
    }
    @PostMapping("/update")
    public R update(@RequestBody Role role){
        return R.out(roleService.updateById(role));
    }
}
